﻿<%@ WebHandler Language="C#" Class="ThumbnailConverter" %>

using System;
using System.Web;
using System.IO;
using System.Drawing;

public class ThumbnailConverter : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string fileFullPath = context.Request.QueryString["location"];

        fileFullPath = Path.Combine(context.Request.PhysicalApplicationPath, fileFullPath);

        // Resize the image
        using (Image tempImage = new Bitmap(Image.FromFile(fileFullPath)))
        {
            int imageHeight = 100;
            int imageWidth = 100;

            // Now make the thumbnail size of image
            using (Image finalImage = tempImage.GetThumbnailImage(imageWidth, imageHeight, new Image.GetThumbnailImageAbort(CancelExecution), IntPtr.Zero))
            {
                finalImage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
    }
 
    public bool IsReusable {
        get {
            return true;
        }
    }

    private bool CancelExecution()
    {
        return false;
    }

}